<!-- left column -->

    <div class="box">
        <div class="box-body solist">
            <div class="box-form form-inline" id='SearchForm'>
                <a href="javascript:;" class="btn btn-primary bg-pink btn-big" id='createBtn'>
                    添加一级分类
                </a>

                <?php if('yes' == $is_admin){?>
                    <div class="form-group">
                        <label>品牌 : &nbsp;</label>
                        <select name="brand_id" style='width:150px;' class='form-control'>
                            <option value="">请选择</option>
                            <?php
                            foreach ($brand_opts as $key => $opts) {
                            ?>
                                <option value="<?=$opts['id'] ?>" <?php if(isset($search['brand_id']) && $search['brand_id'] == $opts['id']) echo 'selected';?>><?=$opts['name'] ?></option>
                            <?php
                            }
                            ?>
                        </select>
                    </div>
                    <button type="button" class="btn btn-default" id='searchBtn'>搜索</button>
                <?php }?>
            </div>
            <table class="table table-bordered text-center" id='IndexTab'>
                <thead>
                    <tr>
                        <!-- <th>编号</th> -->
                        <th>分类图片</th>
                        <th>分类名</th>
                        <th>创建时间</th>
                        <th>显示图片开关</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    <?php
                    if(!empty($categoryList)){
                    foreach ($categoryList as $key=>$category) {
                        $left_width = '35';
                        $left_width = ($category['level']-1) * $left_width;
                        if(0 == $left_width) $left_width = 5;
                    ?>
                        <tr style='text-align: center;'>
                            <!-- <td><?= $category['code']?></td> -->
                            <td>
                                <?php if(1 == $category['is_showimg'] && !empty($category['imageurl'])){?>
                                    <img id="picurl" src="<?= $category['imageurl']?>" width="133" height="50">
                                <?php }?>
                            </td>
                            <td style='text-align: left;padding-left: <?= $left_width?>px;'><?= $category['name']?></td>
                            <td><?= $category['create_time']?></td>
                            <td>
                                <?php if(1 == $category['is_showimg']){?>
                                    开
                                <?php }else{?>
                                    关
                                <?php }?>
                            </td>
                            <td>
                                <a class="btn btn-default btn-xs btn-flat margin" href='<?=base_url()?>index.php/admin/category/create/<?= $category['id']?>' tag='edit_link'>添加</a>
                                <a class="btn btn-default btn-xs btn-flat margin" href='<?=base_url()?>index.php/admin/category/edit/<?= $category['id']?>' tag='edit_link'>编辑</a>
                                <a class="btn btn-default btn-xs btn-flat margin" href='javascript:;' byid="<?= $category['id']?>" status="<?=$category['is_showimg']?>" tag='enable_link'>
                                    <?php if(1 == $category['is_showimg']){?>
                                        关闭图片
                                    <?php }else{?>
                                        开启图片
                                    <?php }?>
                                </a>
                                <?php if('yes' == $is_admin){?>
                                    <a class="btn btn-default btn-xs btn-flat margin" href='javascript:;' byid="<?= $category['id']?>" tag='delete_link'>删除</a>
                                <?php }?>
                            </td>
                        </tr>
                    <?php
                    }
                    }
                    ?>
                </tbody>
            </table>
        </div>
        <!-- /.box-body -->
    </div>

<script src="<?= base_url()?>style/plugins/jQuery/jquery-2.2.3.min.js"></script>
<script src="<?= base_url()?>style/bootstrap/js/bootstrap.min.js"></script>
<script src="<?= base_url()?>style/dist/js/app.min.js"></script>
<!-- <script src="../dist/js/demo.js"></script> -->

<script type="text/javascript">
$(function(){
    var is_submit = 1;
    $('a[tag=delete_link]').on('click',function(){
        if(confirm('确定要删除吗？')){
            $.get('<?=base_url()?>index.php/admin/<?= $module?>/destroy/'+$(this).attr('byid'),function(rest){
                $('#searchBtn').click();
            });
        }
        return false;
    });
    $('#createBtn').on('click',function (){
        location.href = base_url+'index.php/admin/<?= $module?>/create';
    });
    $('#searchBtn').on('click',function(){
        var param = {};
        $('#SearchForm input[name],select[name]').each(function(){
            if($(this).val() != ''){
                param[$(this).attr('name')] = $(this).val();
            }
        });
        if(param['brand_id'] && param['brand_id'] > 0){
            window.localStorage.setItem('admin_category_brand_id',param['brand_id']);
        }else{
            window.localStorage.setItem('admin_category_brand_id',0);
            // window.localStorage.mzadmin_category_brand_id = 0;
        }
        param['cur_page'] = 1;
        searchList(param);
        return false;
    });
    $('#SearchForm input[name]').on({
        'keypress':function (event){
            var e = window.event||event;
            if(13 == e.keyCode){
                $('#searchBtn').click();
            }
        }
    });
    //开启关闭图片
    $('a[tag=enable_link').on('click',function(){
        var param = {};
        param['status'] = $(this).attr('status');
        $.get('<?=base_url()?>index.php/admin/<?= $module?>/enable/'+$(this).attr('byid'),param,function(rest){
            $('#searchBtn').click();
        });
    });
});
</script>
<script src="<?= base_url()?>style/js/vendors.js" type="text/javascript"></script>
<script src="<?= base_url()?>style/js/index.js" type="text/javascript"></script>

</body>
</html>
